local keymap = vim.keymap
vim.g.mapleader = ","

keymap.set("n", "<space>", "za")

keymap.set("n", "<C-h>", "<C-w>h")
keymap.set("n", "<C-j>", "<C-w>j")
keymap.set("n", "<C-k>", "<C-w>k")
keymap.set("n", "<C-l>", "<C-w>l")

-- keymap.set("t", "<Esc>", "<C-\\><C-n>")
keymap.set("t", "<C-h>", "<C-\\><C-n><C-w>h")
keymap.set("t", "<C-j>", "<C-\\><C-n><C-w>j")
keymap.set("t", "<C-k>", "<C-\\><C-n><C-w>k")
keymap.set("t", "<C-l>", "<C-\\><C-n><C-w>l")

-- 选中刚粘贴的文本
vim.cmd([[nmap <expr> gp "`[" . strpart(getregtype(), 0, 1) . "`]"]])

-- 删除行尾空格
vim.cmd([[nmap <F3> :%s/\s\+$//e<CR>]])

function adj_size(zoom)
  font = vim.opt.guifont['_value']
  size = tonumber(string.match(font, "%d+$")) + zoom
  if size >= 6 and size <= 20 then
    font_size = string.format("Hack Nerd Font Mono:h%d", size)
    fontwide_size = string.format("微软雅黑:h%d", size)
    vim.opt.guifont = font_size
    vim.opt.guifontwide = fontwide_size
    -- print("set font_size=%d", size)
  end
end
keymap.set("n", "<C-->", function() adj_size(-1) end)
keymap.set("n", "<C-=>", function() adj_size(1) end)

keymap.set("n", "<leader>=", ":set fenc=utf-8<CR>")

vim.cmd([[nmap <Esc><Esc> :nohlsearch<CR>]])

vim.cmd([[imap <leader><leader> <C-v><tab>]])
vim.cmd([[nmap <leader>v yi":!start <C-r>"<CR>]])
vim.cmd([[vmap <leader>v y<Esc>:!start <C-r>"<CR>]])
